/*
 * Proto Streamer
 * Copyright (C) 2009 John Pritchard.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */
package p.s.t;

import p.s.m.Service;
import alto.io.u.Array;
import alto.io.u.Lobjmap;
import java.util.Enumeration;
import java.util.Hashtable;
import java.lang.reflect.InvocationTargetException;

/**
 * Map service manager.
 * 
 * @author jdp
 */
public final class Map
    extends p.s.m.Manager
{

    public final static Map Instance = new Map();
    static {
        Instance.start();
    }
    public final static Slot Get(Object identity, Class<? extends Service> group){
        return (Slot)Instance.get(identity,group);
    }


    private final Hashtable<Class<? extends Slot>, Slot.Constructor> ctors;


    private Map(){
        super();
        this.ctors = new Hashtable<Class<? extends Slot>, Slot.Constructor>();
    }


    public Slot newInstance(Object id, Class<? extends Service> group)
        throws NoSuchMethodException, InstantiationException, IllegalAccessException,
               IllegalArgumentException, InvocationTargetException
    {
        Class<? extends Slot> sgroup = (Class<? extends Slot>)group;
        Slot.Constructor ctor = this.ctors.get(sgroup);
        if (null == ctor){
            ctor = new Slot.Constructor(sgroup);
            this.ctors.put(sgroup,ctor);
        }
        return ctor.newInstance(id);
    }
}
